fix(VVirtualScroll): preserve measured heights when items change to prevent scroll jump - #23066
Open
waterWang wants to merge 1 commit into
Open
Conversation
…revent scroll jump When the items array changes (e.g. an item is removed via splice), the sizes and offsets arrays were completely reset, causing all previously measured heights to be lost. The offsets would then be recalculated using the default estimate (16px), which is far from the actual measured heights, causing a visible scroll position jump. Fix: preserve existing height measurements for items that remain at the same index after the items array changes. This keeps the offsets largely accurate and prevents the scroll position from jumping. Closes vuetifyjs#22610
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When the
itemsarray changes (e.g. an item is removed viasplice), theVVirtualScrollcomponent completely resets itssizesandoffsetsarrays. This causes all previously measured heights to be lost, and offsets are recalculated using the default 16px estimate — which is far from actual measured heights — causing a visible scroll position jump.Root Cause
In
packages/vuetify/src/composables/virtual.ts, thewatch(items, ...)handler:Every item change discards all measured heights, forcing
getSize()to fall back to the defaultitemHeight(16px). If actual items are 50px tall,offsets[500]drops from 25000 to 8000, causingpaddingTopand the scroll position to jump.Fix
Preserve existing height measurements for items that remain at the same index after the items array changes:
This keeps offsets largely accurate when items are added or removed, preventing the scroll position from jumping.
Closes #22610